<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8"/>
    <title>resource list</title>
    <link rel="stylesheet" th:href="@{/css/css.css}">
    <link rel="stylesheet" th:href="@{/jquery-treetable/stylesheets/jquery.treetable.css}">
    <link rel="stylesheet" th:href="@{/jquery-treetable/stylesheets/jquery.treetable.theme.default.css}">
    <style>
        #table th, #table td {
            font-size: 14px;
            padding: 8px;
        }

    </style>
</head>
<body>
<div class="message" th:text="${msg}" th:if="${msg!=null}"></div>
<table id="table">
    <thead>
    <tr>
        <th>名称</th>
        <th>类型</th>
        <th>URL路径</th>
        <th>权限字符串</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>

    <tr th:each="resource:${resourceList}" th:attr="data-tt-id=${resource.id}"
        th:attrappend="data-tt-parent-id=${resource.parentId}">

        <td th:text="${resource.name}"></td>
        <td th:text="${resource.type.info}"></td>
        <td th:text="${resource.url}"></td>
        <td th:text="${resource.permission}"></td>
        <td>

            <shiro:hasPermission name="resource:add">
                <a th:href="'/resource/'+${resource.id}+'/appendChild'" th:if="${resource.type.info}=='菜单'">添加子节点</a>
            </shiro:hasPermission>

            <shiro:hasPermission name="resource:update">
                <a th:href="'/resource/'+${resource.id}+'/update'">修改</a>
            </shiro:hasPermission>

            <shiro:hasPermission name="resource:delete">
                <a href="#" class="deleteBtn" th:attr="data-id=${resource.id}" th:if="${not resource.rootNode}">删除</a>
            </shiro:hasPermission>
        </td>
    </tr>
    </tbody>
</table>

<script th:src="@{/js/jquery-1.11.0.min.js}"></script>
<script th:src="@{/jquery-treetable/javascripts/src/jquery.treetable.js}"></script>
<script>
    $(function () {
        //删除根节点attr;
        $("tr[data-tt-parent-id='0']").removeAttr("data-tt-parent-id");

        $("#table").treetable({expandable: true}).treetable("expandNode", 1);
        $(".deleteBtn").click(function () {
            if (confirm("确认删除吗?")) {
                location.href = "/resource/" + $(this).data("id") + "/delete";
            }
        });
    });
</script>
</body>
</html>